<template>
	<view>
		properties_name {{ goods_name }}-
		price:{{goods_prise}}
		<view class='goodsNav'>
			<uni-goods-nav :fill="true" :options="options" :buttonGroup="buttonGroup" @click="onClick"
				@buttonClick="buttonClick" />
		</view>

	</view>
</template>

<script>
	// import uni-goods-nav

	
	import cart from 'unpackage/dist/dev/mp-weixin/pages/cart/cart';
	import {
		mapState,
		mapGetters,
		mapMutations,
		mapActions
	} from 'vuex'
	export default {
		computed: {
			...mapState(['goods_count', 'cart']),
			...mapGetters(['total'])
		},
		data() {

			return {
				goods_name: '',
				goods_prise:'',
			
				options: [{
					icon: 'headphones',
					text: '客服'
				}, {
					icon: 'shop',
					text: '店铺',
					info: 2,
					infoBackgroundColor: '#007aff',
					infoColor: "red"
				}, {
					icon: 'cart',
					text: '购物车',
					info: 0
				}],
				buttonGroup: [{
						text: '加入购物车',
						backgroundColor: '#ff0000',
						color: '#fff'
					},
					{
						text: '立即购买',
						backgroundColor: '#ffa200',
						color: '#fff'
					}
				]
			};
		},
		methods: {
			...mapMutations(['addToCart']),

			onClick(e) {
				console.log(e);
			},

			buttonClick(e) {
				if (e.index == 1) {
					uni.showToast({
						// title:'点击了立即购买'

					})
				} else if (e.index == 0) {
					uni.showToast({
						title: '加入购物车',
					})

					let ogj = {
						goods_name: this.goods_name,
						price:this.goods_prise,
						goods_count: 1
					}					
					this.addToCart(ogj)
				}
			},

		},

		onLoad(option) {
			let res = uni.getStorageSync('cart')
			let item = JSON.parse(option.item)
			this.goods_name = item.properties_name
			this.goods_prise = item.price
			this.options[2].info = this.total
		},

		watch: {
			total: {
				handler(newVal) {
					this.options[2].info = newVal
				}
			}
		}

	}
</script>

<style lang="scss">
	.goodsNav {
		width: 100%;
		position: fixed;
		buttom: 0;
		left: 0;
	}
</style>